package com.wiloon.monitor.sync;

import com.wiloon.kafka.KafkaClient;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by roy on 12/11/16;
 */
public class MonitorSync {
    private static Logger logger = LoggerFactory.getLogger(MonitorSync.class);

    public static void main(String[] args) {
        logger.info("status-sync start.");
        KafkaClient kafkaClient = new KafkaClient("kafka.wiloon.com:9092", "status-sync", "q_monitor");
        Icon icon = new Icon();

        while (true) {
            try {
                ConsumerRecords<String, String> records = kafkaClient.poll();
                for (ConsumerRecord<String, String> record : records) {
                    String msg = record.value();
                    logger.info("kafka msg:{}", msg);
                    if ("true".equals(msg)) {
                        String new_message = "<img>/home/roy/apps/qq-monitor/img/new_message_30.png</img>";
                        icon.setPath(new_message);
                    } else {
                        String normal = "<img>/home/roy/apps/qq-monitor/img/normal_30.png</img>";
                        icon.setPath(normal);
                    }
                }
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
